package cn.tedu.egmvc2.controller;

import cn.tedu.egmvc2.mapper.EmpMapper;
import cn.tedu.egmvc2.pojo.dto.EmpInsertDTO;
import cn.tedu.egmvc2.pojo.entity.Emp;
import cn.tedu.egmvc2.pojo.vo.EmpSelectVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/emp/")
public class EmpController {
    @Autowired
    private EmpMapper empMapper;

    @PostMapping("insert")
    public String insert(EmpInsertDTO empInsertDTO){
        Emp emp = new Emp();
        BeanUtils.copyProperties(empInsertDTO,emp);
        int i = empMapper.insert(emp);
        return "添加成功,受影响的行数:"+i;
    }

    @GetMapping("select")
    public List<EmpSelectVO> select(){
        return empMapper.select();
    }

    @GetMapping("update")
    public String update(Emp emp){
        int i = empMapper.update(emp);
        return "修改成功,受影响的行数:"+i;
    }

    @GetMapping("delete")
    public String delete(int id){
        int i = empMapper.delete(id);
        return "修改成功,受影响的行数"+i;
    }
}
